from typing import Optional
from PySide6.QtCore import QObject, QThread, qDebug, Signal
from Libs.Jinritemai.Spider import Jinritemai


class JinritemaiThread(QObject):
    finished = Signal()
    resp = Signal(dict)

    def __init__(self, parent=None, *args, **kwargs):
        super(JinritemaiThread, self).__init__(parent)
        self.cookies = kwargs.get('cookies', '')
        self.screenInfo = kwargs.get('screenInfo', '')
        self.verifyFp = kwargs.get('verifyFp', '')
        self.msToken = kwargs.get('msToken', '')
        self.ua = kwargs.get('ua', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')
        self.s = None

    def initJinritemai(self):
        self.s = Jinritemai()
        self.s.cookies = self.cookies
        self.s.verifyFp = self.verifyFp
        self.s.msToken = self.msToken
        self.s.ua = self.ua
        self.s.screenInfo = self.screenInfo

    def getSearchFilter(self):
        qDebug(f'JinritemaiThread running')
        data = []
        if not self.s or isinstance(self.s, Jinritemai):
            self.initJinritemai()
        data = self.s.getSearchFilter()
        self.resp.emit(data)
        self.finished.emit()

    
